package cn.kgc.controller;

import cn.kgc.pojo.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class LoginAndRegisterController {
    @RequestMapping("login")
    @ResponseBody
    public JSON login(User user){
        User selectUser=new User();
        selectUser.setBirthday(new Date());
        selectUser.setId(1);
        selectUser.setPassword("123456");
        selectUser.setUserName("张三");
        return (JSON) JSON.toJSON(selectUser);
    }
    @RequestMapping("login1")
    @ResponseBody
    public JSON login1(User user){
        User selectUser=new User();
        selectUser.setId(1);
        selectUser.setBirthday(new Date());
        selectUser.setPassword("123456");
        selectUser.setUserName("张三1");
        User selectUser1=new User();
        selectUser1.setId(2);
        selectUser1.setBirthday(new Date());
        selectUser1.setPassword("123456");
        selectUser1.setUserName("张三2");
        List<User> userList=new ArrayList<>();
        userList.add(selectUser);
        userList.add(selectUser1);
        return (JSON) JSON.toJSON(userList);
    }
    @RequestMapping("delUser")
    @ResponseBody
    public String login(String id){
        System.out.println("要删除的用户id为:"+id);

        return "true";
    }
    @RequestMapping("modifyUser")
    @ResponseBody
    public String modifyUser(@RequestBody User user){
        System.out.println(user.getUserName());

        return "true";
    }
    @ResponseBody
    @RequestMapping("/todate")
    public String todate(){
        Date date =new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date1 = sdf.format(date);
        String json = JSON.toJSONString(date1);
        return "today:"+json;
    }

}
